<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.icss.th.subjects.pojo.Subject"%>
<%@ page import="com.icss.th.subjects.service.SubjectService"%>
<%
	String context = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<title>题海</title>
<meta charset="UTF-8">
<link href="<%=context%>/includes/css/style.css" rel="stylesheet" type="text/css">
<link href="<%=context%>/includes/css/jquery-ui.min.css" rel="stylesheet" type="text/css">
</head>
<body>
	<div id=wrapper>
		<div id=content>
			<div id=u class="top-bg">
				<div id=user>
					<span style="float: left; padding-left: 20px; padding-top: 2px;">
						<img src="<%=context%>/includes/images/title.png" width="71" height="34">
					</span>
					<div id=userMenu>
						<a href="#">登录</a>&nbsp;<font color="#f68d00" size="2">|</font>&nbsp;
						<a href="#">快速入口</a>&nbsp;<font color="#f68d00">|</font>&nbsp;
						<a href="#">合作接口</a>
					</div>
				</div>
			</div>
		</div>
		<div id=m style="margin-top:140px;width:540px">
			<div style="padding-left: 10px; margin-bottom: 10px; height: 60px;">
				<input type="hidden" name="subjectId" id="subjectId" value="118">
				<input type="hidden" id="subjectNameH" value="GRE">
				<ul>
					<li style="width: 100px; font-size: 16px; font-weight: bold; height: 40px; line-height: 40px; color: #666; float: left;">检索题库：</li>
					<li id="subjectName" style="font-size: 20px; font-weight: bold; height: 40px; line-height: 40px; color: #666; float: left;">GRE</li>
					<li style="width: 80px; text-align: center; font-size: 12px; font-weight: bold; height: 40px; line-height: 40px; color: #666; float: left;">
						<a href="javascript:void(0)" class="s_botton" onClick="choseSubject()">选择</a>
					</li>
				</ul>
			</div>
			<div id=fm>
					<span class="input-bg1">
						<input class="s_ipt" maxlength="38" placeholder="输入试题题目" type="text" name="keyword" id="keyword" x-webkit-speech />
					</span>
					<span style="color: #FFF">
						<input type="button" onclick="_search()" value="搜　索" class="s_btn" onMouseDown="this.className='s_btn s_btn_h'" onMouseOut="this.className='s_btn'">
					</span>
			</div>
			<div style="text-align:center; margin-top: 30px;margin-right:8px">
				<span style="margin-right: 20px;">
					<a href="<%=context%>/adsearch.html" class="s_botton">高级搜索</a>
				</span>
				<span>
					<a href="#" class="s_botton">添加试题</a>
				</span>
			</div>
		</div>

		<div id=ftCon>
			<p id=lh>
				<a href="#" onclick="AddFavorite()">加入收藏夹</a>
			</p>
			<p>
				<a href="#">关于我们</a>&nbsp;&nbsp;|&nbsp;&nbsp; <a href="#">加入我们</a>&nbsp;&nbsp;|&nbsp;&nbsp;
				<a href="#">支持与捐赠</a>&nbsp;&nbsp;|&nbsp;&nbsp; <a href="#">开放接口</a>
			</p>
			<p id=cp>
				©2013&nbsp;Tihai.org&nbsp;北京题海科技有限公司&nbsp;&nbsp;<a href="#">使用必读</a>&nbsp;&nbsp;&nbsp;
				<a href="#" target="_blank">冀ICP备08007478号</a>&nbsp;
			</p>
		</div>
		
		<%
					Subject root = SubjectService.getRoot();
					if (root != null)
					{
						List<Subject> list = root.getChildren();
						if (list  != null && !list.isEmpty())
						{
				%>
		<div id="tabs" style="display: none">
			<div id="tabs0" style="position: absolute;">
				<ul class="menu0" id="menu0">
				<%
					for (int i = 0; i < list.size(); i++)
					{
						Subject level1 = list.get(i);
				%>
					<li onClick="setSubjectTab(<%=i%>)" class="<%=i == 0? "hover" : ""%>">&nbsp;<%=level1.getName()%></li>
				<%} %>
				</ul>
			</div>
			<div class="main scrollbar" id="main0" style="position: absolute;">
				<%
					for (int i = 0; i < list.size(); i++)
					{
						Subject level1 = list.get(i);
						List<Subject> list2 = level1.getChildren();
						if (list2  != null && !list2.isEmpty())
						{
				%>
				<ul class="<%=i == 0? "block" : ""%>">
				<% 
					for (Subject level2 : list2)
					{
				%>
					<li><a href="#" id="<%=level2.getId()%>" onclick="setSubject(this, '')"><%=level2.getName()%></a></li>
				<%}%>
				</ul>
				<%}} %>
			</div>
		</div>
		<%
				}
			}
		%>
	</div>
<script src="<%=context%>/includes/js/jquery-1.10.0.min.js" type="text/javascript"></script>
<script src="<%=context%>/includes/js/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$("#keyword").keypress(function(event){
		if ( event.which == 13 ) {
			_search();
		}
	});

	$(function(){
		$("#subjectName").html($("#subjectNameH").val());
	});

	function _search(){
		if ($.trim($("#keyword").val())){
			var path = '<%=context%>/search?';
			path += 'subjectId=' + $("#subjectId").val();
			path += '&keyword=' + encodeURI(encodeURI($("#keyword").val()));
			location.href = path;
		}else{
			location.reload();
		}
	}
	
	var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
	document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F42ed38773b3a5508770816baea5faa33' type='text/javascript'%3E%3C/script%3E"));

//弹出试题科目选择框
function choseSubject(){
	$("#tabs").dialog({
		modal: true,
		height: 500,
		width: 700,
		resizable: false,
		draggable: false,
		title: '选择您需要的科目'
	});
}

//切换科目选择tab页
function setSubjectTab(n){
	$("li", $("#menu0")).each(function(i, o){
		o.className = i == n? "hover" : "";
	});
	
	$("ul", $("#main0")).each(function(i, o){
		o.style.display = i == n? "block" : "none";
	});
}

//选定一个科目
function setSubject(li, isSubmit){
	$("#subjectId").val(li.id);
	$("#subjectNameH").val(li.innerHTML);
	$("#subjectName").html(li.innerHTML);
	$("#tabs").dialog( "close" );
	
	if(isSubmit == 'isSubmit'){
		optionSubmit('subject', '');
	}
}	

function AddFavorite(){
	var sURL = window.location;
	var sTitle = document.title;
    try{
        window.external.addFavorite(sURL, sTitle);
    }catch (e){
        try{
            window.sidebar.addPanel(sTitle, sURL, "");
        }catch (e){
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
</script>
</body>
</html>
